package com.longdaji.decoration.data.network;
import android.util.Log;
import io.reactivex.subscribers.ResourceSubscriber;
import retrofit2.HttpException;

/**
 * Created by longtao on 2018/1/7.
 */

public abstract class CommonSubscriber<T> extends ResourceSubscriber<T> {

    @Override
    public void onNext(T t) {
        onSuccess(t);
    }

    @Override
    public void onError(Throwable e) {
        Log.d("LoginPresenter",e.toString());
        String msg = "";
        if (e instanceof ApiException) {
            msg = e.toString();
        } else if (e instanceof HttpException) {
            msg = "数据加载错误！";
        } else {
            msg = "未知错误！";
        }
        onFailed(msg);

    }

    @Override
    public void onComplete() {
    }

    public abstract void onSuccess(T t);

    public abstract void onFailed(String msg);
}
